/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aspect.example;
import java.util.Random;
import static aspect.example.AspectTest.r;
import aspect.util.Trig;
import aspect.util.Vector2;
/**
*
* @author millerv
*/
public class NoiseTest {
public static void generateTerrain(float[][] floats, int w) {
System.out.println("w");
float m = 2 * Trig.PI / w;
for (int k = 1; k < 50; k++) {
float phase = r.nextFloat() * 2 * Trig.PI;
for (int a = 0; a < 10; a++) {
Vector2 vec = Vector2.fromAngle(r.nextFloat() * 360, 1.0f);
for (int i = 0; i < w; i++) {
for (int j = 0; j < w; j++) {
//floats[i][j] += noise(i, j, k, m, xphase, zphase);
floats[i][j] += noise(i, j, k, m, phase, vec);
}
}
}
}
}
/*
public static float noise(float x, float z, float freq, float m, float xphase, float zphase) {
float amp = amplitude(freq);
return noise(x, freq, m, xphase) * noise(z, freq, m, zphase) * amp;
}
private static float noise(float x, float freq, float m, float phase) {
float f = Trig.sin(Trig.toDegrees(x * freq * m + phase));
return (f / 2.0f) + 1;
}*/
private static float noise(float x, float z, float freq, float m, float phase, Vector2 vec) {
float amp = amplitude(freq);
return Trig.sin(Trig.toDegrees((x * vec.x + z * vec.y) * freq * m) + phase)* amp;
}
public static float amplitude(float freq) {
return (1 / freq) * 3;
}
}